﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FirstFloor.ModernUI.Windows.Controls;
using IsikFx.Project.ClientApp.Helpers;
using IsikFx.Project.CommonTypes;
using IsikFx.Project.CommonTypes.CRUD;
using IsikFx.Project.CommonTypes.User;

namespace IsikFx.Project.ClientApp.Content
{
    /// <summary>
    /// Interaction logic for UpdateGoal.xaml
    /// </summary>
    public partial class UpdateGoal : UserControl
    {
        User user;
        ModernDialog dialog = new ModernDialog();
        public UpdateGoal()
        {
            InitializeComponent();
            SetValuesFromDB();

        }

        private void btn_Click_1(object sender, RoutedEventArgs e)
        {
            bool isInsert = false; // İlk hedef girişi mi
            try
            {
                Goal goal = Helpers.Helper.GetAgentGoal();
                if (goal.AccountGoal == 0 && goal.FundGoal == 0)
                    isInsert = true;
                user = Helper.CurrentUser;
                dialog = new ModernDialog();
                IsikFxWcfService.ServiceClient client = new IsikFxWcfService.ServiceClient();
                CrudResponseMessage responseMessage = client.UpdateAgentGoal(Int32.Parse(user.UserID), txtFundGoal.Text, txtAccountGoal.Text, Helper.USD, isInsert);
                if (!responseMessage.HasError && responseMessage.Response.AffectedRows > 0)
                {
                    dialog.Content = "Fon Güncelleme İşleminiz Başarıyla Gerçekleştirildi.";
                    dialog.Title = "Sonuç";
                }
                else
                {
                    dialog.Content = responseMessage.ErrorMessage;
                    dialog.Title = "Sonuç";
                }
                dialog.ShowDialog();
            }
            catch (Exception ex)
            {
                dialog.Content = "Hata";
                dialog.Title = ex.Message;
                dialog.ShowDialog();
            }
        }



        private void SetValuesFromDB()
        {
            Goal goal = new Goal();
            goal = Helper.GetAgentGoal();
            if (goal != null)
            {
                txtAccountGoal.Text = goal.AccountGoal.ToString();
                txtFundGoal.Text = goal.FundGoal.ToString();
            }
        }
    }
}

